< Prev(J) / Next(K) > / View :

Filename: /text/sbasic/shared/03090410.xhp

(section: switch) (bookmark: bm_id3148554)
Switch function

Switch 関数

Switch Function [Runtime]
Switch 関数 [実行時](hd_id3148554.1)

Evaluates a list of arguments, consisting of an expression followed by a value. The Switch function returns a value that is associated with the expression that is passed by this function.
表式と値のペアを引数として、これら引数のリストを対象とした判定処理を行います。Switch 関数は、与えられた表式がどの引数に該当するかを判定して、対応する値を返します。(par_id3148522.2)

(/section: switch)

Syntax:
構文:(hd_id3154863.3)

Switch (Expression1, Value1[, Expression2, Value2[..., Expression_n, Value_n]])
Switch (Expression1, Value1[, Expression2, Value2[..., Expression_n, Value_n]])(par_id3155934.4)

Parameters:
パラメータ:(hd_id3149119.5)

The Switch function evaluates the expressions from left to right, and then returns the value that is assigned to the function expression. If expression and value are not given as a pair, a runtime error occurs.
Switch 関数は、表式を左から右の順番で判定してゆき、関数に与えられた表式に該当する値を返します。表式と値がペアとして指定されていない場合は、実行時エラーが発生します。(par_id3153894.6)

Expression: The expression that you want to evaluate.
Expression: 評価の対象となる表式。(par_id3153990.7)

Value: The value that you want to return if the expression is True.
Value: 表式が該当した場合に返す値。(par_id3153394.8)

In the following example, the Switch function assigns the appropriate gender to the name that is passed to the function:
下記の例では、Switch 関数により、与えられた名前の性別を判定させています。(par_id3153346.9)

(embed text/sbasic/shared/00000003.xhp#errorcode : linkinfo)

Error Codes

エラーコード(hd_id3152869.37)

(/embed text/sbasic/shared/00000003.xhp#errorcode)

(embed text/sbasic/shared/00000003.xhp#err5 : linkinfo)

5 Invalid procedure call
5 無効なプロシージャー呼び出しです (par_id3150891.41)

(/embed text/sbasic/shared/00000003.xhp#err5)

Example:
例:(hd_id3159157.10)

Sub ExampleSwitch
Sub ExampleSwitch(par_id3147573.11)

Dim sGender As String
Dim sGender As String(par_id3143270.12)

sGender = GetGenderIndex( "John" )
sGender = GetGenderIndex( "John" )(par_id3149579.13)

MsgBox sGender
MsgBox sGender(par_id3153626.14)

End Sub
End Sub(par_id3147560.15)

Function GetGenderIndex (sName As String) As String
Function GetGenderIndex (sName As String) As String(par_id3154758.17)

GetGenderIndex = Switch(sName = "Jane", "female", sName = "John", "male")
GetGenderIndex = Switch(sName = "Jane", "female", sName = "John", "male")(par_id3153361.18)

End Function
End Function(par_id3154939.19)


< Prev / Next >